package com.power.controller.DefectAd;

import com.alibaba.fastjson.JSONObject;
import com.power.ov.ResultDataTable;
import com.power.pojo.Sovle;
import com.power.service.DefectAdService;
import com.power.service.impl.defectAdServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

/**
 * Created/**
 * Created with IntelliJ IDEA.
 * User: lh
 * Date: 2020/09/29 21:01
 * Description:
 * Version: V1.0
 */
@WebServlet("/updateSolve")
public class updateSolveServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        req.setCharacterEncoding("utf-8");
        BufferedReader br=req.getReader();
        String string=br.readLine();
        System.out.println("================"+string);

        Sovle sovle= JSONObject.parseObject(string,Sovle.class);
        List<Map> list = (List) sovle.getKey2();
        System.out.println(list);
        for ( Map ap:list) {
            sovle.setDefect_details_id(Integer.parseInt(ap.get("defect_details_id").toString()));
        }

        DefectAdService defectAdService=new defectAdServiceImpl();
        resp.setContentType("application/json;charset=utf-8");
        ResultDataTable resultData = new ResultDataTable();
        int result =0;
        try {
            result=defectAdService.addSovle(sovle);
            if (result > 0){
                resultData.setCode(200);
                resultData.setMessage("添加成功");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        resp.setContentType("application/json;charset=utf-8");
        resp.getWriter().write(JSONObject.toJSONString(resultData));
        resp.getWriter().flush();
        resp.getWriter().close();


    }
}
